package cz.muni.fi.pa165.sme.services.converter;

import cz.muni.fi.pa165.sme.api.to.SportActivityRecordTO;
import cz.muni.fi.pa165.sme.dao.entity.SportActivityRecord;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.convert.converter.Converter;

/**
 * @author jirankova
 */
public class SportActivityRecord2SportActivityRecordTOConverter implements
		Converter<SportActivityRecord, SportActivityRecordTO> {

	@Autowired private User2UserTOConverter userTOConverter;
	@Autowired private SportActivity2SportActivityTOConverter sportActivityTOConverter;

	@Override
	public SportActivityRecordTO convert(final SportActivityRecord source) {
		if(source == null) {
			return null;
		}

		final SportActivityRecordTO target = new SportActivityRecordTO();

		target.setActivityStart(source.getActivityStart());
		target.setActivityStop(source.getActivityStop());
		target.setDistance(source.getDistance());
		target.setDuration(source.getDuration());
		target.setId(source.getId());
		target.setSportActivity(sportActivityTOConverter.convert(source.getSportActivity()));
		target.setUser(userTOConverter.convert(source.getUser()));

		return target;
	}
}
